<!DOCTYPE html>
<html>
<head>
<title>duang for select elements</title>
<script type="text/javascript">
	document.write("<p>hello world</p>");
	function do_change(elt){
		var text = elt[elt.selectedIndex].innerHTML;
		if(!text.match(/\[/))
			elt[elt.selectedIndex].innerHTML += " [duang]";
		var is_all_seleted = true;
		for(var i=0;i<elt.length;++i){
			if(!elt[i].innerHTML.match(/\[/)){
				is_all_seleted = false;
				break;
			}
		}
		if(is_all_seleted){
			alert("all duang!!!\nand reset it!!!");
			for(var i=0;i<elt.length;++i){
				elt[i].innerHTML = elt[i].innerHTML.replace(/\s\[.*\]/,"")
			}
		}
	}

	function do_change_ex(me){
		//console.log(this.toString());
		//console.log(me.toString());
		var text = me[me.selectedIndex].innerHTML;
		if(!text.match(/\[/)){
			me[me.selectedIndex].text_bak = me[me.selectedIndex].innerHTML;
			me[me.selectedIndex].innerHTML += " [duang]";
			me[me.selectedIndex].is_changed = true;
		}
		var is_all_seleted = true;
		for(var i=0;i<me.length;++i){
			if(!me[i].is_changed){
				is_all_seleted = false;
				break;
			}
		}
		if(is_all_seleted){
			alert("all duang!!!\nand reset it!!!");
			for(var i=0;i<me.length;++i){
				me[i].innerHTML = me[i].text_bak;
				me[i].is_changed = false;
			}
		}
	}
	function on_change_test(){
		console.log(window.event);
	}
	function on_submit(){
		alert(event);
		return false;
	}
	window.onbeforeunload = function(){
		return "hello world!!";
	}
</script>
</head>
<body>
	<form id="frm_main" action="#" method="post" >
		<select id="slt" onchange="on_change_test();">
			<option value="opt_1">opt A</option>
			<option value="opt_2">opt B</option>
			<option value="opt_3">opt C</option>
			<option value="opt_4">opt D</option>
			<option value="opt_5">opt E</option>
		</select>
		<input type="submit" value="close window" onclick="on_submit();" />
	</form>
</body>
</html>